<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@include file="../AllLoad.jsp" %>
<script type="text/javascript" src="${server}/app/js/jedate.js"></script>
<link id="jeDateSkin" type="text/css" rel="stylesheet" href="${server}/app/css/jedate.css">
<script type="text/javascript" src="${server}/app/js/formatedate.js"></script>
   <style type="text/css">
	.image-upload {
	    left: 0;
	    opacity: 0;
	    position: absolute;
	    top: 0;
	    width:100%;
	}
</style>
<script type="text/javascript">
	$("#form1").ajaxForm({
		dataType:"json",
		success:function(data){
			if(data.status == "success"){
				$("#showImg").val(data.msg);
			}else{
				alert(data.msg);
			}
		},
		error:function(){
			alert("上传文件异常...");
		}
	});
	
	// 文件上传
	function doUploadFile(){
		$("#form1").submit();
	}
	
	// 导入
	function doImport(){
		var fileUrl = $("#showImg").val();
		if(null == fileUrl || fileUrl == ""){
			$.CurrentNavtab.alertmsg("warn","请先上传要导入的订单数据");
			return;
		}
		var point = fileUrl.lastIndexOf(".");
		var fileType = fileUrl.substring(point+1);
		if(fileType != "xls"){
			$.CurrentNavtab.alertmsg("warn","请上传.xls的excel文件，如果不是该类型，可以打开文件进行另存为.xls");
			return;
		}
		var confirm = window.confirm("确定操作吗？");
		if(confirm){
			$("#importMsg").show();
			$.post(server+'/orders/doImport',{'fileUrl':fileUrl},function(data){
				$("#importMsg").hide();
				$.CurrentNavtab.alertmsg("warn",data.msg);
			});
		}
	}
</script>
<div class="bjui-pageHeader">
	<form method="post" id="pagerForm" action="${server}/orders?order_source=${order_source}&order_export=${order_export}&spec_order=${spec_order}" data-toggle="ajaxsearch" >
		<ul class="bjui-searchBar">
			<li>
				<label class="trtitle01">姓名：</label>
				<input type="text" size="8" id="name" name="orders.name" value="${name }" class="form-control"/>
			</li>
			<li>
				<label class="trtitle01">产品名称：</label>
				<input type="text" size="8" id="pro_name" name="orders.pro_name" value="${pro_name }" class="form-control"/>
			</li>
			<li>
				<label class="trtitle01">电话：</label>
				<input type="text" size="8" id="mobile" name="orders.mobile" value="${mobile }" class="form-control"/>
			</li>
			<li>
				<label class="trtitle01">订单来源：</label>
				<input type="text" size="8" id="source" name="orders.source" value="${source }" class="form-control"/>
			</li>
			
			<li>
				<label class="trtitle01">订单时间：</label>
				<input type="text" size="8" name="createStartDate" id="createStartDate" value="${createStartDate }"/>
				<input type="text" size="8" name="createEndDate" id="createEndDate" value="${createEndDate }"/>
			</li>
			<li>
				<label class="trtitle01">订单状态：</label>
				<select name="orders.state" id="state" data-toggle="selectpicker">
					<option value="" <c:if test="${empty state }">selected = "selected"</c:if>>全部</option>
					<option value="0" <c:if test="${state==0 }">selected = "selected"</c:if>>待审核</option>
       				<option value="1" <c:if test="${state==1 }">selected = "selected"</c:if>>待发货</option>
       				<option value="2" <c:if test="${state==2 }">selected = "selected"</c:if>>已发货</option>
       				<option value="3" <c:if test="${state==3 }">selected = "selected"</c:if>>已签收 </option>
       				<option value="4" <c:if test="${state==4 }">selected = "selected"</c:if>>已回款</option>
       				<option value="5" <c:if test="${state==5 }">selected = "selected"</c:if>>未审过</option>
       				<option value="6" <c:if test="${state==6 }">selected = "selected"</c:if>>待联系</option>
       				<option value="7" <c:if test="${state==7 }">selected = "selected"</c:if>>已拒收</option>
				</select>
			</li>
			<li>
				<label class="trtitle01">客户类型：</label>
				<select name="orders.xian" id="xian" data-toggle="selectpicker">
					<option value="" <c:if test="${empty xian }">selected = "selected"</c:if>>全部</option>
       				<option value="1" <c:if test="${xian==1 }">selected = "selected"</c:if>>一线</option>
       				<option value="2" <c:if test="${xian==2 }">selected = "selected"</c:if>>二线</option>
       				<option value="3" <c:if test="${xian==3 }">selected = "selected"</c:if>>三线 </option>
				</select>
			</li>
			<li>
			 	<button type="submit" class="btn-default" data-icon="search">查询</button>
			</li>
		</ul>
	</form>
</div>
<%-- <c:if test="${order_status==1 }">
	<div class="bjui-pageContent">
	    <div class="bjui-headBar">
	        <ul>
	        	<li style="float: left"><a href="${server}/jsp/orders/update.jsp" class="btn btn-default btn-sm" data-icon="save" data-id="control-user-add_view" data-toggle="navtab" data-title="添加订单" >添加订单 </a></li>
				<li class="left"><a href="${server}/orders/delete" class="btn btn-default btn-sm" data-icon="trash-o" data-toggle="doajaxchecked" data-type="post" data-confirm-msg="确定要删除选中项吗？" data-idname="idws" data-group="idww">删除订单</a></li>
				<li class="left"><a onclick="daochu()" id="daochu" class="btn btn-default" data-toggle="navtab" data-icon="button">导出订单(根据查询条件)</a></li>
	       </ul>
	    </div>
	</div>
</c:if> --%>
<c:if test="${order_export==1 }">
	<div class="bjui-pageContent">
	    <div class="bjui-headBar">
	        <ul>
	        	<li style="float: left"><a href="${server}/jsp/orders/update.jsp" class="btn btn-default btn-sm" data-icon="save" data-id="control-user-add_view" data-toggle="navtab" data-title="添加订单" >添加订单 </a></li>
				<li class="left"><a href="${server}/orders/delete" class="btn btn-default btn-sm" data-icon="trash-o" data-toggle="doajaxchecked" data-type="post" data-confirm-msg="确定要删除选中项吗？" data-idname="idws" data-group="idww">删除订单</a></li>
				<li class="left"><a onclick="daochu()" id="daochu" class="btn btn-default" data-toggle="navtab" data-icon="button">导出订单(根据查询条件)</a></li>
				<c:if test="${not empty spec_order }">
					<li class="left">
					 	<button type="submit" onclick="doImport('${role}');" style="margin-left:230px;" class="btn-default" data-icon="search">导入</button>
					</li>
					<li id="importMsg" style="display:none;">	
					 	<img src="${server}/styles/images/loading.gif" alt="" />
					 	<div style="text-align:center;">正在导入</div>
					</li>
				</c:if>
	       </ul>
	    </div>
	</div>
	<c:if test="${not empty spec_order }">
		<div class="bjui-pageContent" style="position:absolute;left:360px;top:43px;">
			<form id="form1" action="${server}/fileUpload" method="post" enctype="multipart/form-data" class="pageForm">
				<div class="pageFormContent" data-layout-h="0">
			        <table class="table table-condensed table-hover" data-width="100%">
				    	<tbody>
				            <tr>
				            	<td>
				                	<input id="showImg" type="text" readonly="readonly" placeholder="请选择要导入的文件" value="">
				                	<a href="javascript:void(0);" class="btn btn-green">上传
										<input id="file" name="file" type="file" class="image-upload" onchange="doUploadFile();"/>
									</a>
				                </td>
				            </tr>
				        </tbody>
			        </table>
				</div>
			</form>
		</div>
	</c:if>
</c:if>
<div class="pageContent bjui-resizeGrid" style="top: 29px; bottom: 28px;">
	<table data-toggle="tablefixed" data-layout-h="0" data-nowrap="true">
		<thead>
			<tr align="center">
				<th width="35" style="text-align: center;"><input type="checkbox" class="checkboxCtrl" data-group="ids" data-toggle="icheck"/></th>
				<th width="100">产品名称</th>
				<th width="50">购买数量</th>
				<th width="50">订单总额</th>
				<th width="100">创建日期</th>
				<th width="80">订单来源</th>
				<th width="60">订单状态</th>
				<th width="60">客户类型</th>
				<th width="60">姓名</th>
				<c:if test="${order_export==1 }"><th width="80">号码</th></c:if>
				<th width="80">地址</th>
				<th width="80">快递单号</th>
				<th width="120">操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${page.result}" var="orders">
				<tr>
					<td  width="35" style="text-align: center;"><input type="checkbox" name="ids" data-toggle="icheck" value="${orders.id}" ></td>
					<td title="${orders.pro_name}">${orders.pro_name}</td>
					<td>${orders.num}</td>
					<td>${orders.price}</td>
					<td><fmt:formatDate value="${orders.create_date}" pattern="yyyy-MM-dd HH:mm:ss"/> </td>
					<td title="${orders.source}">${orders.source}</td>
					<td>
						<c:if test="${orders.state==0}">待审核</c:if>
						<c:if test="${orders.state==1}">待发货</c:if>
						<c:if test="${orders.state==2}">已发货</c:if>
						<c:if test="${orders.state==3}">已签收</c:if>
						<c:if test="${orders.state==4}">已回款</c:if>
						<c:if test="${orders.state==5}">未审过</c:if>
						<c:if test="${orders.state==6}">待联系</c:if>
						<c:if test="${orders.state==7}">已拒收</c:if>
					</td>
					<td>
						<c:if test="${orders.xian==1}">一线</c:if>
						<c:if test="${orders.xian==2}">二线</c:if>
						<c:if test="${orders.xian==3}">三线</c:if>
					</td>
					<td title="${orders.name}">${orders.name}</td>
					<c:if test="${order_export==1}">
					<td title="${orders.mobile}">
						<a href="${server}/orders/orderList?mobile=${orders.mobile}" data-toggle="navtab" data-icon="edit" style="color:blue" data-id="control-role-update_view" data-reload-warn="本页已有打开的内容，确定将刷新本页内容，是否继续？"  data-title="回访-${orders.mobile}">${orders.mobile }</a>
						<%-- <a href="${server}/orders/orderList?mobile=${orders.mobile}" data-reload-warn="本页已有打开的内容，确定将刷新本页内容，是否继续？" style="color:blue" data-id="${orders.mobile}" data-toggle="navtab" data-title="列表">${orders.mobile}</a> --%>
					</td>
					</c:if>
					<td title="${orders.area}${orders.address}">${orders.area}${orders.address}</td>
					<td title="${orders.order_number}">${orders.order_number}</td>
					<td>
						<a href="${server}/orders/detail?id=${orders.id}&stat=1" class="btn btn-default" data-toggle="navtab" data-icon="edit" data-id="control-role-update_view" data-reload-warn="本页已有打开的内容，确定将刷新本页内容，是否继续？"  data-title="编辑-${orders.name}">编辑</a>
						<c:if test="${orders.state==0 }"><a class="btn btn-red" data-toggle="doajax" data-type="post" data-confirm-msg="确定要删除该条数据吗？" href="${server}/orders/delete?ids=${orders.id}">删除</a></c:if>
					</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
</div>
<script type="text/javascript">

	jeDate({
		dateCell:"#createStartDate",
		format:"YYYY-MM-DD",
		isinitVal:false,
		okfun:function(val){alert(val)}
	})
	jeDate({
		dateCell:"#createEndDate",
		format:"YYYY-MM-DD",
		isinitVal:false,
		okfun:function(val){alert(val)}
	})

	function daochu(){
		var pro_name = $("#pro_name").val();
		var name = $("#name").val();
		var mobile = $("#mobile").val();
		var source = $("#source").val();
		var state = $("#state").val();
		var xian = $("#xian").val();
		var createStartDate = $("#createStartDate").val();
		var createEndDate = $("#createEndDate").val();
		var order_source = '${order_source}';
		var order_export = '${order_export}';
		var spec_order = '${spec_order}';
		window.location.href=server+"/orders/exportExl?pro_name="+pro_name+"&name="+name+"&mobile="+mobile+"&source="+source+"&state="+state+"&xian="+xian+"&createStartDate="+createStartDate+"&createEndDate="+createEndDate+"&order_source="+order_source+"&order_export="+order_export+"&spec_order="+spec_order;
	}
</script>
<%@include file="../page.jsp" %>